<template>
  <!-- 非首保车辆维护 -->
  <div>
    <!--条件筛选-->
    <TopFilter :list="topFilterList" :cols="3" labelWidth="90" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <!--操作 -->
    <button-area :style="{ paddingLeft: '80px' }"></button-area>
    <!-- 列筛选-->
    <FilterTable
      ref="table"
      columnsRef="repair-repairBusiness-notFirstMaintenance_index"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :isSelectColumn="false"
      :onColumnsChange="(columns) => (this.columns = columns)"
    >
      <!--列操作-->
      <template slot="controls">
        <el-button size="small" type="primary" icon="el-icon-upload" @click="exportClick">导出模板</el-button>
        <multiuse-button size="small" icon="el-icon-upload" @click="showImportFun()">Ecxel导入</multiuse-button>
      </template>
    </FilterTable>

    <!--抽屉 -->
    <BaseDialog
      :visible.sync="showImport"
      :closable="false"
      icon="el-icon-upload"
      title="导入"
      width="800px"
      destroyOnClose
      :containerStyle="{ height: 'calc(100% - 120px)', overflow: 'auto', paddingBottom: '60px' }"
    >
      <importExcel @close="showImport = false" @importclose="close()" :url="`${config.uploadUrl}/api/dmscloud.activity/ttNonFirstVehicle/uploadVinTem`" />
    </BaseDialog>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { getListByPage, getListForExport, deleteById } from '@/api/repair/repairBusiness/notFirstMaintenance';
import { exportExcelFile, notifyAction } from '@/utils';
import importExcel from './importExcel';
import config from '@/assets/js/config';

// 延保订单查询
export default {
  name: 'notFirstMaintenance',
  components: { importExcel },
  mixins: [dictionary],
  data() {
    return {
      config: config,
      fetchParams: { xhrAbort: false },
      fetchApi: getListByPage,
      columns: this.createTableColumns(),
      formData: {},
      selectFlag: false,
      topFilterList: this.createTopFilterList(),
      showImport: false,
      exportLoading: false,
    };
  },
  created() {},
  methods: {
    exportClick() {
      this.$confirm('此操作将下载excel模板, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        this.exportLoading = true;
        getListForExport().then((res) => {
          exportExcelFile(res.data, '非首保车辆维护模板');
          this.exportLoading = false;
        });
      });
    },

    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
        },
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: (props) => {
            return <span>{props.row.index + 1}</span>;
          },
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          render: (props, h) => {
            return (
              <div>
                <multiuse-button size="mini" type="text" onClick={() => this.assignHandle(props.row)}>
                  删除
                </multiuse-button>
              </div>
            );
          },
        },
        {
          title: 'VIN',
          dataIndex: 'vin',
        },
        {
          title: '创建人',
          dataIndex: 'createdBy',
        },
        {
          title: '创建时间',
          dataIndex: 'createdAt',
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
        },
      ];
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    // Excel更新导入
    showImportFun() {
      this.showImport = true;
    },
    close() {
      this.showImport = false;
      this.fetchParams = Object.assign({}, this.fetchParams);
    },
    async assignHandle(row) {
      this.$confirm('是否确认删除', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(async () =>  {
        const res = await deleteById(row);
        if (res.resultCode === 200) {
          console.log(1231232)
          if (res.errMsg) {
            notifyAction(res.errMsg, 'error');
          } else {
            notifyAction('删除成功！');
          }
        }
        this.fetchParams = Object.assign({}, this.fetchParams);
      });
      
      
    },
  },
};
</script>

<style lang="less" scoped></style>
